package com.yanxml.spring.history.v3.demo0_component_scan_xml;

import com.yanxml.spring.history.v3.demo0_component_scan_xml.service.UserService;
import com.yanxml.spring.history.v3.demo1_component_scan.config.JavaConfig;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

public class StartAppDemo0 {
    public static void main(String[] args) {
//        ApplicationContext applicationContext = new AnnotationConfigApplicationContext();
//        ApplicationContext applicationContext = new AnnotationConfigApplicationContext(JavaConfig.class);
        ApplicationContext applicationContext = new FileSystemXmlApplicationContext("classpath:applicationContext.xml");
        System.out.println(applicationContext.getBean(UserService.class));
    }
}


// demo1_1: 出现异常情况
//Exception in thread "main" java.lang.IllegalStateException: org.springframework.context.annotation.AnnotationConfigApplicationContext@49c2faae has not been refreshed yet
//        at org.springframework.context.support.AbstractApplicationContext.assertBeanFactoryActive(AbstractApplicationContext.java:1096)
//        at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1126)
//        at com.yanxml.spring.history.v3.demo1_component_scan.StartAppDemo1.main(StartAppDemo1.java:12)

// demo1_2:
// com.yanxml.spring.history.v3.demo1_component_scan.service.UserService@29176cc1